﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesktopApplication
{
    public class DBhelper
    {
        private static readonly string conString = "server=.;database=Blogs;uid=sa;pwd=cultural0725.";


        //连接数据库 封装类
        public static DataTable GetDataTable(string sql)
        {
            //string conString = "server=.;database=Blogs;uid=sa;pwd=cultural0725.";

            SqlConnection connection = new SqlConnection(conString);

            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, conString);

            DataTable table = new DataTable();

            connection.Open();

            dataAdapter.Fill(table);

            return table;

        }


        //增删改查 封装类
        public static int AddOrUpdateOrDelete(string sql)
        {
            //string conString = "server=.;database=Blogs;uid=sa;pwd=cultural0725.";

            SqlConnection connection = new SqlConnection(conString);

            SqlCommand command = new SqlCommand(sql,connection);

            connection.Open();

            return command.ExecuteNonQuery();


        }

    }
}
